// pages/topic_list/topic_list.js
import { request } from "../../request/index.js";
import { showModal, showToast, uploadFile, chooseImage, showLoading } from "../../util/AsyncWx.js";
let a = ''
Page({

  /**
   * 页面的初始数据
   */
  data: {
    categoryList: [],
    topicList: [],
    showInput: false,
    allDiscuss: [],
    checkedAll: true,
    currentIndex: 0,
    checkedCategory: false,
    categoryTopicList: [],
    name: '',
    isCollect: '',
    num: '2'
  },

  /**
   * 生命周期函数--监听页面加载
   */

  async onShow() {
    if (a) {
      a = false
    } else {
      var that = this
      var allDiscuss = wx.getStorageSync('allDiscuss');
      that.setData({
        allDiscuss: allDiscuss
      })
      const result = await request({ url: "/topic/getTopicAll" })
      const res = await request({ url: "/category/getCategoryAllName" })
      that.setData({
        topicList: result,
        categoryList: res,
      })
    }
  },
  all_topic() {
    this.setData({
      checkedAll: true,
      checkedCategory: false
    })

  },
  async handleItemTap(e) {
    //获取点击的索引
    var that = this
    const { index, name } = e.currentTarget.dataset;
    that.setData({
      currentIndex: index,
      checkedAll: false,
      checkedCategory: true,
      name: name
    })
    var categoryname = name
    // that.setData({
    //   categoryTopicList:''
    // })
    const result = await request({ url: "/topic/getTopicByCategoryName", data: { categoryname } })
    that.setData({
      categoryTopicList: result,

    })
  },
  handleImagePreview: function (e) {
    a = true
    var that = this
    var url = e.currentTarget.dataset.url
    wx.previewImage({
      current: url,
      urls: [url],
    });

  },


})